package com.systop.asset.controller;

import java.util.List;

import com.systop.asset.entity.RestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.systop.asset.entity.MaterialCategory;
import com.systop.asset.service.IMaterialCategoryService;

/**
 * 耗材类别Controller
 * 
 * @author mc
 * @date 2025-06-26
 */
@RestController
@RequestMapping("/system/materialCategory")
public class MaterialCategoryController
{
    @Autowired
    private IMaterialCategoryService materialCategoryService;

    /**
     * 查询耗材类别列表
     */
    @GetMapping("/list")
    public RestResponse list(MaterialCategory materialCategory)
    {

        List<MaterialCategory> list = materialCategoryService.getCategory(materialCategory);
        return RestResponse.success(list);
    }

    /**
     * 获取耗材类别详细信息
     */
    @GetMapping(value = "/{id}")
    public RestResponse getInfo(@PathVariable("id") Long id)
    {
        return RestResponse.success(materialCategoryService.selectMaterialCategoryById(id));
    }

    /**
     * 新增耗材类别
     */
    @PostMapping
    public RestResponse add(@RequestBody MaterialCategory materialCategory)
    {
        if(materialCategoryService.insertMaterialCategory(materialCategory)!=0){
            return RestResponse.success();
        }
        return RestResponse.failure(500,"添加失败,名称已存在");
    }

    /**
     * 修改耗材类别
     */
    @PutMapping
    public RestResponse edit(@RequestBody MaterialCategory materialCategory)
    {
        if(materialCategoryService.updateMaterialCategory(materialCategory)!=0){
            return RestResponse.success();
        }
        return RestResponse.failure(500,"修改失败,名称已存在");
    }

    /**
     * 删除耗材类别
     */
	@DeleteMapping("/{ids}")
    public RestResponse remove(@PathVariable Long[] ids)
    {
        return RestResponse.success(materialCategoryService.deleteMaterialCategoryByIds(ids));
    }
}
